<template>
  <div class="app-container" style="position: relative; height: calc(100vh - 117px);">
    <div class="container">

      <el-tabs v-model="status" type="card" @tab-click="handleOrder">
        <el-tab-pane name="-9">
          <span slot="label"><i class="el-icon-s-order"></i> 全部订单</span>
        </el-tab-pane>
        <el-tab-pane name="0">
          <span slot="label"><i class="el-icon-bank-card"></i> 未支付</span>
        </el-tab-pane>
        <el-tab-pane name="1">
          <span slot="label"><i class="el-icon-refrigerator"></i> 未发货</span>
        </el-tab-pane>
        <el-tab-pane name="2">
          <span slot="label"><i class="el-icon-truck"></i> 待收货</span>
        </el-tab-pane>
        <el-tab-pane name="3">
          <span slot="label"><i class="el-icon-document"></i> 待评价</span>
        </el-tab-pane>
        <el-tab-pane name="4">
          <span slot="label"><i class="el-icon-circle-check"></i> 交易完成</span>
        </el-tab-pane>
        <el-tab-pane name="-1">
          <span slot="label"><i class="el-icon-back"></i> 退款中</span>
        </el-tab-pane>
        <el-tab-pane name="-2">
          <span slot="label"><i class="el-icon-finished"></i> 已退款</span>
        </el-tab-pane>
      </el-tabs>
      <!--工具栏-->
      <div class="head-container">
        <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="addOrder()">新增</el-button>
        <!-- 搜索 -->
<!--        <el-input v-model="distributorId" clearable placeholder="经销商名称" style="width: 200px;" class="filter-item">
          <el-autocomplete v-model="distributorID"  placeholder="经销商名称"  :trigger-on-focus="false" :fetch-suggestions="querySearchAsync" @select="handleSelect">
          </el-autocomplete>
        </el-input>-->
        <el-autocomplete v-model="distributorId" clearable placeholder="经销商名称" class="filter-item" :trigger-on-focus="true" :fetch-suggestions="querySearchAsync" @select="handleSelect" />
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item"
                  @keyup.enter.native="toQuery"/>
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
        </el-select>
        <el-select v-model="orderType" clearable placeholder="订单类型" class="filter-item" style="width: 130px">
          <el-option
            v-for="item in typeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-date-picker
          v-model="createTime"
          :default-time="['00:00:00','23:59:59']"
          type="daterange"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
        <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
        <!-- 新增 -->
        <el-button
          type="danger"
          class="filter-item"
          size="mini"
          icon="el-icon-refresh"
          @click="toQuery"
        >刷新
        </el-button>
      </div>
      <!--表单组件-->
      <eForm ref="form" :is-add="isAdd"/>
      <eDetail ref="form1" :is-add="isAdd"/>
      <eRefund ref="form2" :is-add="isAdd"/>
      <editOrder ref="form3" :is-add="isAdd"/>
      <eRemark ref="form4" :is-add="isAdd"/>
      <ePrint ref="form5" :is-add="isAdd" :print-list="checkList" :to-query="toQuery"/>
      <addOrder ref="form6" :is-add="isAdd"/>
      <editSkuPrice ref="form7" :is-add="isAdd"/>

      <!--订单数据统计-->
      <div class="order-caculate">
        <a class="caculate-title">订单数 : <span class="caculate-num">{{ caculateInfo.orderNum }}</span></a>
        <a class="caculate-title">商品数 : <span class="caculate-num">{{ caculateInfo.storeNum }}</span></a>
        <a class="caculate-title">订单金额 : <span class="caculate-num">{{ caculateInfo.orderPrice }}</span></a>
        <a class="caculate-title">客户数 : <span class="caculate-num">{{ caculateInfo.userNum }}</span></a>
      </div>

      <!--表格渲染-->
      <el-table ref="multipleTable" v-loading="loading" :data="data" size="small" style="width: 100%;"
                @selection-change="handleSelectionChange">
        <el-table-column :selectable="checkboxT" type="selection" width="50"/>
        <el-table-column prop="orderId" width="140" label="订单号">
          <template slot-scope="scope">
            <span>{{ scope.row.orderId }}</span>
            <p>{{ scope.row.pinkName }}</p>
          </template>
        </el-table-column>
        <el-table-column prop="realName" label="用户昵称">
          <template slot-scope="scope">
            <span>{{ scope.row.userDTO.nickname }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="distributorName" label="经销商名称">
          <template slot-scope="scope">
            <span>{{ scope.row.distributorName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="cartInfoList" width="370" label="商品信息">
          <template slot-scope="scope">
            <!-- <div v-for="(item,index) in scope.row.cartInfoList"
            :key="index"
            v-if="item.cartInfoMap.productInfo.attrInfo">
              <span>
                <img style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                  :src="item.cartInfoMap.productInfo.attrInfo.image"
                >
              </span>
              <span>{{ item.cartInfoMap.productInfo.storeName }}&nbsp;{{ item.cartInfoMap.productInfo.attrInfo.suk }}</span>
              <span> | ￥{{ item.cartInfoMap.truePrice }}×{{ item.cartInfoMap.cartNum }}</span>
            </div>
            <div v-else>
              <span>
                <img
                style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                :src="item.cartInfoMap.productInfo.image">
              </span>
              <span>{{ item.cartInfoMap.productInfo.storeName }}</span>
              <span> | ￥{{ item.cartInfoMap.truePrice }}×{{ item.cartInfoMap.cartNum }}</span>
            </div> -->
            <div v-for="(item,index) in scope.row.cartInfoList"
                 :key="index">
                <span v-if="item.cartInfoMap.productInfo.attrInfo">
                  <img style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                       :src="item.cartInfoMap.productInfo.attrInfo.image"
                  >
                </span>
              <span v-else>
                  <img
                    style="width: 30px;height: 30px;margin:0;cursor: pointer;"
                    :src="item.cartInfoMap.productInfo.image">
              </span>
              <span>
                  {{ item.cartInfoMap.productInfo.attrInfo.sku }} | {{ item.cartInfoMap.productInfo.attrInfo.barCode }} |
                  {{ item.cartInfoMap.productInfo.storeName }}
              </span>
              <span> | ￥{{ item.cartInfoMap.truePrice }}×{{ item.cartInfoMap.cartNum }}</span>
              <span v-if="scope.row._status == 1">
                <el-button
                  v-permission="['admin','YXDISTRIBUTOR_EDIT']"
                  size="mini"
                  type="primary"
                  icon="el-icon-edit"
                  @click="editSkuPrice(item)"
                  style="height:22px;width:40px;top: auto;"></el-button>
              </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="payPrice" label="实际支付"/>
        <el-table-column prop="payIntegral" label="消费积分"/>
        <el-table-column prop="payTypeName" label="支付状态"/>
        <el-table-column prop="statusName" label="订单状态">
          <template slot-scope="scope">
            <span v-html="scope.row.statusName"></span>
          </template>
        </el-table-column>
        <el-table-column prop="addTime" width="160" label="创建时间">
          <template slot-scope="scope">
            <span>{{ formatTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="checkPermission(['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT','YXSTOREORDER_DELETE'])"
                         label="操作" width="200" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
              size="mini"
              type="primary"
              @click="toDetailURL(scope.row.id)"
            >
              订单详情
            </el-button>
            <el-dropdown size="mini" split-button type="primary" trigger="click">
              操作
              <el-dropdown-menu slot="dropdown">
                <!-- <el-dropdown-item
                  v-if="
                    scope.row.paid == 0 &&
                    scope.row.payType == 'offline' &&
                    scope.row.isConfirmOffline == 1
                  "
                >
                  <el-button
                    v-permission="[
                      'admin',
                      'YXSTOREORDER_ALL',
                      'YXSTOREORDER_EDIT',
                    ]"
                    size="mini"
                    type="warning"
                    @click="openConfirm"
                    >确认打款</el-button
                  >
                </el-dropdown-item> -->
                <el-dropdown-item
                  v-if="
                    scope.row.paid == 0 &&
                    scope.row.payType == 'offline' &&
                    scope.row.isConfirmOffline == 1">
                  <el-popover
                    :ref="scope.row.id"
                    v-permission="[
                      'admin',
                      'YXSTOREORDER_ALL',
                      'YXSTOREORDER_DELETE',
                    ]"
                    placement="top"
                    width="180">
                    <p>确定经销商已经打款？</p>
                    <div style="text-align: right; margin: 0">
                      <el-button
                        size="mini"
                        type="text"
                        @click="$refs[scope.row.id+1].doClose()">取消
                      </el-button>
                      <el-button
                        :loading="delLoading"
                        type="primary"
                        size="mini"
                        @click="subConfirmPayment(scope.row.id)">确定
                      </el-button>
                    </div>
                    <el-button slot="reference" type="warning" size="mini"
                    >确认打款
                    </el-button
                    >
                  </el-popover>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button
                    v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
                    size="mini"
                    type="success"
                    @click="remark(scope.row)"
                  >
                    订单备注
                  </el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button
                    v-if="scope.row._status == 2"
                    v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
                    size="mini"
                    type="primary"
                    @click="edit(scope.row)"
                  >
                    去发货
                  </el-button>
                  <el-button
                    v-if="scope.row._status == 4"
                    v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
                    size="mini"
                    type="primary"
                    @click="edit(scope.row)"
                  >
                    修改快递
                  </el-button>
                </el-dropdown-item>
                <el-dropdown-item>
                  <el-button
                    v-if="scope.row._status == 3"
                    v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
                    size="mini"
                    type="primary"
                    @click="refund(scope.row)"
                  >
                    立刻退款
                  </el-button>
                </el-dropdown-item>
                <el-dropdown-item v-if="scope.row._status == 1">
                  <el-button
                    v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
                    size="mini"
                    type="primary"
                    @click="editOrder(scope.row)"
                  >
                    修改订单
                  </el-button>
                </el-dropdown-item>
                <el-dropdown-item v-if="scope.row._status == 1">
                  <el-popover
                    :ref="scope.row.id"
                    v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_DELETE']"
                    placement="top"
                    width="180"
                  >
                    <p>确定删除本条数据吗？</p>
                    <div style="text-align: right; margin: 0">
                      <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
                      <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定
                      </el-button>
                    </div>
                    <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini">删除</el-button>
                  </el-popover>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--添加订单打印及订单导出功能 2020.04.13 changxh-->
    <el-footer class="footer-contains">
      <div class="footer-search">
        <el-checkbox v-model="printChecked" @change="batchSelection" style="margin-right: 20px;"></el-checkbox>
        <el-select v-model="batchHandle" @change="handlePrintOption" clearable placeholder="批量操作" class="filter-item"
                   style="width: 130px; margin-right: 8px;">
          <el-option
            v-for="item in handleOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-select v-model="batchExport" @change="handleExportOption" clearable placeholder="批量导出" class="filter-item"
                   style="width: 130px">
          <el-option
            v-for="item in exportOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <!--分页组件-->
      <el-pagination
        :total="total"
        :current-page="page + 1"
        style="margin-top: 8px;"
        layout="total, prev, pager, next, sizes"
        @size-change="sizeChange"
        @current-change="pageChange"/>
    </el-footer>
  </div>
</template>

<script>
import checkPermission from "@/utils/permission";
import initData from "@/mixins/crud";
import {del} from "@/api/yxStoreOrder";
import {confirmPayment} from "@/api/yxStoreOrder";
import eForm from "./form";
import eDetail from "./detail1";
import eRefund from "./refund";
import editOrder from "./edit";
import addOrder from './add'
import eRemark from "./remark";
import ePrint from "./print";
import editSkuPrice from "./skupriceform"
import {formatTime} from "@/utils/index";
import {gett} from "@/api/visits";
import {queryDistributorList} from "../../../api/yxDistributor";

export default {
  components: {eForm, eDetail, eRefund, editOrder, eRemark, ePrint, addOrder, editSkuPrice},
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      status: '-9',
      orderType: '0',
      createTime: '',
      distributorList: [],
      distributorId:'',
      checkList: [],
      printChecked: false,
      batchHandle: '',
      batchExport: '',
      listContent: [],
      queryTypeOptions: [
        {key: 'orderId', display_name: '订单号'},
        {key: 'realName', display_name: '用户姓名'},
        {key: 'userPhone', display_name: '用户电话'}
      ],
      statusOptions: [
        {value: '0', label: '未支付'},
        {value: '1', label: '未发货'},
        {value: '2', label: '待收货'},
        {value: '3', label: '待评价'},
        {value: '4', label: '交易完成'},
        // { value: '5', label: '待核销' },
        {value: '-1', label: '退款中'},
        {value: '-2', label: '已退款'},
        {value: '-4', label: '已删除'}
      ],
      typeOptions: [
        {value: '0', label: '所有订单'},
        {value: '1', label: '普通订单'},
        {value: '2', label: '拼团订单'},
        {value: '3', label: '秒杀订单'},
        {value: '4', label: '砍价订单'},
        {value: '5', label: '核销订单'},
        {value: '6', label: '积分订单'}
      ],
      handleOptions: [
        {value: '', label: '批量操作'},
        {value: '0', label: '批量打印'},
      ],
      exportOptions: [
        {value: '', label: '批量导出'},
        {value: '0', label: '导出全部'},
        {value: '1', label: '导出选中'},
      ],
      caculateInfo: {
        orderNum: 0,
        storeNum: 0,
        orderPrice: 0,
        userNum: 0,
      },
    }
  },
  created() {
    this.$nextTick(() => {
      this.init();
      this.getCaculateInfo();
      this.getDistributorInfo();
    })
  },
  methods: {
    getDistributorInfo() {
      queryDistributorList().then(async res => {
        let data = res.distributorList;
        if(data) {
          this.distributorList = res.distributorList;
        }
      }).catch(res => {
        return this.$message({
          message:res.msg,
          type: 'error'
        });
      })
    },
    querySearchAsync(queryString, cb) {
      debugger
      //在这里为这个数组中每一个对象加一个value字段, 因为autocomplete只识别value字段并在下拉列中显示，所以我从新封装了
      let distributorList = this.distributorList;
      // console.log(productList)

      let programList = [];
      for(let i=0;i<this.distributorList.length;i++){
        programList.push({'value':distributorList[i].distributorId +'--'+distributorList[i].distributorName})
      }
      // console.log(programList.values())
      let results = queryString ? programList.filter(this.createStateFilter(queryString)) : programList;
      //基本思路就是实现一个过滤器，过滤存在你输入字段的所有数据。
      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 1000 * Math.random());
    },
    createStateFilter(queryString) {
      return (product) => {
        return (product.value.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
      };
    },
    handleSelect(item) {
      this.distributorId = item.value
      /*var strs= new Array();
      strs = item.value.split("--")
      this.distributorId = strs[0]*/
    },


    toDetailURL(id) {
      this.$router.push({path: '/order/detail/' + id})
    },
    formatTime,
    checkPermission,
    handleOrder(tab, event) {
      this.status = tab.name
      this.toQuery();
      this.getCaculateInfo();
    },
    beforeInit() {
      this.url = 'api/yxStoreOrder'
      const sort = 'id,desc'
      this.params = {
        page: this.page,
        size: this.size,
        sort: sort,
        orderStatus: this.status,
        orderType: this.orderType,
        createTime: this.createTime,
        distributorId: this.distributorId,
        listContent: this.listContent
      }
      const query = this.query
      const type = query.type
      const value = query.value
      if (type && value) {
        this.params[type] = value
      }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.dleChangePage()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
    subConfirmPayment(id) {
      this.delLoading = true;
      confirmPayment(id)
        .then((res) => {
          this.delLoading = false;
          this.$refs[id].doClose();
          this.dleChangePage();
          this.init();
          this.$notify({
            title: "确认打款成功",
            type: "success",
            duration: 2500,
          });
        })
    },
    add() {
      this.isAdd = true
      this.$refs.form.dialog = true
    },
    edit(data) {
      this.isAdd = false
      const _this = this.$refs.form
      _this.form = {
        id: data.id,
        orderId: data.orderId,
        uid: data.uid,
        realName: data.realName,
        userPhone: data.userPhone,
        userAddress: data.userAddress,
        cartId: data.cartId,
        freightPrice: data.freightPrice,
        totalNum: data.totalNum,
        totalPrice: data.totalPrice,
        totalPostage: data.totalPostage,
        payPrice: data.payPrice,
        payPostage: data.payPostage,
        deductionPrice: data.deductionPrice,
        couponId: data.couponId,
        couponPrice: data.couponPrice,
        paid: data.paid,
        payTime: data.payTime,
        payType: data.payType,
        addTime: data.addTime,
        status: data.status,
        refundStatus: data.refundStatus,
        refundReasonWapImg: data.refundReasonWapImg,
        refundReasonWapExplain: data.refundReasonWapExplain,
        refundReasonTime: data.refundReasonTime,
        refundReasonWap: data.refundReasonWap,
        refundReason: data.refundReason,
        refundPrice: data.refundPrice,
        deliveryName: data.deliveryName,
        deliverySn: data.deliverySn,
        deliveryType: data.deliveryType,
        deliveryId: data.deliveryId,
        gainIntegral: data.gainIntegral,
        useIntegral: data.useIntegral,
        backIntegral: data.backIntegral,
        mark: data.mark,
        isDel: data.isDel,
        unique: data.unique,
        remark: data.remark,
        merId: data.merId,
        isMerCheck: data.isMerCheck,
        combinationId: data.combinationId,
        pinkId: data.pinkId,
        cost: data.cost,
        seckillId: data.seckillId,
        bargainId: data.bargainId,
        verifyCode: data.verifyCode,
        storeId: data.storeId,
        shippingType: data.shippingType,
        isChannel: data.isChannel,
        isRemind: data.isRemind,
        isSystemDel: data.isSystemDel,
        _status: data._status
      }
      _this.dialog = true
    },
    editOrder(data) {
      this.isAdd = false
      const _this = this.$refs.form3
      _this.form = {
        id: data.id,
        orderId: data.orderId,
        uid: data.uid,
        realName: data.realName,
        userPhone: data.userPhone,
        userAddress: data.userAddress,
        cartId: data.cartId,
        freightPrice: data.freightPrice,
        totalNum: data.totalNum,
        totalPrice: data.totalPrice,
        totalPostage: data.totalPostage,
        payPrice: data.payPrice,
        payPostage: data.payPostage,
        deductionPrice: data.deductionPrice,
        couponId: data.couponId,
        couponPrice: data.couponPrice,
        paid: data.paid,
        payTime: data.payTime,
        payType: data.payType,
        addTime: data.addTime,
        status: data.status,
        refundStatus: data.refundStatus,
        refundReasonWapImg: data.refundReasonWapImg,
        refundReasonWapExplain: data.refundReasonWapExplain,
        refundReasonTime: data.refundReasonTime,
        refundReasonWap: data.refundReasonWap,
        refundReason: data.refundReason,
        refundPrice: data.refundPrice,
        deliveryName: data.deliveryName,
        deliveryType: data.deliveryType,
        deliveryId: data.deliveryId,
        gainIntegral: data.gainIntegral,
        useIntegral: data.useIntegral,
        backIntegral: data.backIntegral,
        mark: data.mark,
        isDel: data.isDel,
        unique: data.unique,
        remark: data.remark,
        merId: data.merId,
        isMerCheck: data.isMerCheck,
        combinationId: data.combinationId,
        pinkId: data.pinkId,
        cost: data.cost,
        seckillId: data.seckillId,
        bargainId: data.bargainId,
        verifyCode: data.verifyCode,
        storeId: data.storeId,
        shippingType: data.shippingType,
        isChannel: data.isChannel,
        isRemind: data.isRemind,
        isSystemDel: data.isSystemDel
      }
      _this.dialog = true
    },
    addOrder() {
      this.isAdd = true
      const _this = this.$refs.form6
      _this.form = {
        /*  id: data.id,
          orderId: data.orderId,
          uid: data.uid,
          realName: data.realName,
          userPhone: data.userPhone,
          userAddress: data.userAddress,
          cartId: data.cartId,
          freightPrice: data.freightPrice,
          totalNum: data.totalNum,
          totalPrice: data.totalPrice,
          totalPostage: data.totalPostage,
          payPrice: data.payPrice,
          payPostage: data.payPostage,
          deductionPrice: data.deductionPrice,
          couponId: data.couponId,
          couponPrice: data.couponPrice,
          paid: data.paid,
          payTime: data.payTime,
          payType: data.payType,
          addTime: data.addTime,
          status: data.status,
          refundStatus: data.refundStatus,
          refundReasonWapImg: data.refundReasonWapImg,
          refundReasonWapExplain: data.refundReasonWapExplain,
          refundReasonTime: data.refundReasonTime,
          refundReasonWap: data.refundReasonWap,
          refundReason: data.refundReason,
          refundPrice: data.refundPrice,
          deliveryName: data.deliveryName,
          deliveryType: data.deliveryType,
          deliveryId: data.deliveryId,
          gainIntegral: data.gainIntegral,
          useIntegral: data.useIntegral,
          backIntegral: data.backIntegral,
          mark: data.mark,
          isDel: data.isDel,
          unique: data.unique,
          remark: data.remark,
          merId: data.merId,
          isMerCheck: data.isMerCheck,
          combinationId: data.combinationId,
          pinkId: data.pinkId,
          cost: data.cost,
          seckillId: data.seckillId,
          bargainId: data.bargainId,
          verifyCode: data.verifyCode,
          storeId: data.storeId,
          shippingType: data.shippingType,
          isChannel: data.isChannel,
          isRemind: data.isRemind,
          isSystemDel: data.isSystemDel*/
      }
      _this.dialog = true
    },
    remark(data) {
      this.isAdd = false
      const _this = this.$refs.form4
      _this.form = {
        id: data.id,
        orderId: data.orderId,
        uid: data.uid,
        realName: data.realName,
        userPhone: data.userPhone,
        userAddress: data.userAddress,
        cartId: data.cartId,
        freightPrice: data.freightPrice,
        totalNum: data.totalNum,
        totalPrice: data.totalPrice,
        totalPostage: data.totalPostage,
        payPrice: data.payPrice,
        payPostage: data.payPostage,
        deductionPrice: data.deductionPrice,
        couponId: data.couponId,
        couponPrice: data.couponPrice,
        paid: data.paid,
        payTime: data.payTime,
        payType: data.payType,
        addTime: data.addTime,
        status: data.status,
        refundStatus: data.refundStatus,
        refundReasonWapImg: data.refundReasonWapImg,
        refundReasonWapExplain: data.refundReasonWapExplain,
        refundReasonTime: data.refundReasonTime,
        refundReasonWap: data.refundReasonWap,
        refundReason: data.refundReason,
        refundPrice: data.refundPrice,
        deliveryName: data.deliveryName,
        deliveryType: data.deliveryType,
        deliveryId: data.deliveryId,
        gainIntegral: data.gainIntegral,
        useIntegral: data.useIntegral,
        backIntegral: data.backIntegral,
        mark: data.mark,
        isDel: data.isDel,
        unique: data.unique,
        remark: data.remark,
        merId: data.merId,
        isMerCheck: data.isMerCheck,
        combinationId: data.combinationId,
        pinkId: data.pinkId,
        cost: data.cost,
        seckillId: data.seckillId,
        bargainId: data.bargainId,
        verifyCode: data.verifyCode,
        storeId: data.storeId,
        shippingType: data.shippingType,
        isChannel: data.isChannel,
        isRemind: data.isRemind,
        isSystemDel: data.isSystemDel
      }
      _this.dialog = true
    },
    refund(data) {
      this.isAdd = false
      const _this = this.$refs.form2
      _this.form = {
        id: data.id,
        orderId: data.orderId,
        uid: data.uid,
        realName: data.realName,
        userPhone: data.userPhone,
        userAddress: data.userAddress,
        cartId: data.cartId,
        freightPrice: data.freightPrice,
        totalNum: data.totalNum,
        totalPrice: data.totalPrice,
        totalPostage: data.totalPostage,
        payPrice: data.payPrice,
        payPostage: data.payPostage,
        deductionPrice: data.deductionPrice,
        couponId: data.couponId,
        couponPrice: data.couponPrice,
        paid: data.paid,
        payTime: data.payTime,
        payType: data.payType,
        addTime: data.addTime,
        status: data.status,
        refundStatus: data.refundStatus,
        refundReasonWapImg: data.refundReasonWapImg,
        refundReasonWapExplain: data.refundReasonWapExplain,
        refundReasonTime: data.refundReasonTime,
        refundReasonWap: data.refundReasonWap,
        refundReason: data.refundReason,
        refundPrice: data.refundPrice,
        deliveryName: data.deliveryName,
        deliveryType: data.deliveryType,
        deliveryId: data.deliveryId,
        gainIntegral: data.gainIntegral,
        useIntegral: data.useIntegral,
        backIntegral: data.backIntegral,
        mark: data.mark,
        isDel: data.isDel,
        unique: data.unique,
        remark: data.remark,
        merId: data.merId,
        isMerCheck: data.isMerCheck,
        combinationId: data.combinationId,
        pinkId: data.pinkId,
        cost: data.cost,
        seckillId: data.seckillId,
        bargainId: data.bargainId,
        verifyCode: data.verifyCode,
        storeId: data.storeId,
        shippingType: data.shippingType,
        isChannel: data.isChannel,
        isRemind: data.isRemind,
        isSystemDel: data.isSystemDel
      }
      _this.dialog = true
    },
    detail(data) {
      this.isAdd = false
      const _this = this.$refs.form1
      _this.form = {
        id: data.id,
        orderId: data.orderId,
        payTypeName: data.payTypeName,
        statusName: data.statusName,
        uid: data.uid,
        realName: data.realName,
        userPhone: data.userPhone,
        userAddress: data.userAddress,
        cartId: data.cartId,
        freightPrice: data.freightPrice,
        totalNum: data.totalNum,
        totalPrice: data.totalPrice,
        totalPostage: data.totalPostage,
        payPrice: data.payPrice,
        payPostage: data.payPostage,
        deductionPrice: data.deductionPrice,
        couponId: data.couponId,
        couponPrice: data.couponPrice,
        paid: data.paid,
        payTime: data.payTime,
        payType: data.payType,
        createTime: data.createTime,
        status: data.status,
        refundStatus: data.refundStatus,
        refundReasonWapImg: data.refundReasonWapImg,
        refundReasonWapExplain: data.refundReasonWapExplain,
        refundReasonTime: data.refundReasonTime,
        refundReasonWap: data.refundReasonWap,
        refundReason: data.refundReason,
        refundPrice: data.refundPrice,
        deliveryName: data.deliveryName,
        deliverySn: data.deliverySn,
        deliveryType: data.deliveryType,
        deliveryId: data.deliveryId,
        gainIntegral: data.gainIntegral,
        useIntegral: data.useIntegral,
        backIntegral: data.backIntegral,
        mark: data.mark,
        isDel: data.isDel,
        unique: data.unique,
        remark: data.remark,
        merId: data.merId,
        isMerCheck: data.isMerCheck,
        combinationId: data.combinationId,
        pinkId: data.pinkId,
        cost: data.cost,
        seckillId: data.seckillId,
        bargainId: data.bargainId,
        verifyCode: data.verifyCode,
        storeId: data.storeId,
        shippingType: data.shippingType,
        isChannel: data.isChannel,
        isRemind: data.isRemind,
        isSystemDel: data.isSystemDel,
        nickname: data.userDTO.nickname
      }
      _this.dialog = true
    },
    getCaculateInfo() {
      gett().then(res => {
        this.caculateInfo = {
          orderPrice: res.priceCount,
          orderNum: res.orderCount,
          storeNum: res.goodsCount,
          userNum: res.userCount,
        };
      })
    },
    clearCaculateInfo() {
      this.caculateInfo = {
        orderPrice: 0,
        storeNum: 0,
        orderNum: 0,
        userNum: 0,
      };
    },
    handleSelectionChange(val) {
      this.checkList = val;
      let orderPrice = 0, storeNum = 0, orderNum = 0, userNum = 0;
      if (val.length != 0) {
        this.printChecked = true;
        let user = [];
        val.forEach((item, index) => {
          orderNum += 1;
          orderPrice += item.totalPrice;
          storeNum += item.totalNum;
          user.push(item.userDTO.nickname);
        })
        user = Array.from(new Set(user));
        this.caculateInfo = {
          orderPrice: orderPrice.toFixed(2),
          storeNum: storeNum,
          orderNum: orderNum,
          userNum: user.length,
        };
      } else {
        this.printChecked = false;
        this.clearCaculateInfo();
        // this.getCaculateInfo();
      }
    },
    batchSelection(val) {
      let rows = this.data;
      if (val) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    // 导出选中
    handlePrintOption(val) {
      switch (val) {
        case '0':
          this.getPrintList();
          this.batchHandle = '';
          break;
        default:
          break;
      }
    },
    handleExportOption(val) {
      let list = this.checkList;
      this.page = 0;
      this.size = 10000;
      switch (val) {
        case "0":
          this.listContent = "";
          this.beforeInit();
          this.downloadMethod();
          break;
        case "1":
          if (list.length == 0) {
            this.$message({
              message: '请选择订单',
              type: 'warning'
            });
          } else {
            this.listContent = [];
            list.forEach((item) => {
              this.listContent.push(item.orderId);
            })
            this.listContent = JSON.stringify(this.listContent);
            this.beforeInit();
            this.downloadMethod();
          }
          break;
        default:
          break;
      }
      this.batchExport = "";
    },
    getPrintList() {
      let list = this.checkList;
      if (list.length == 0) {
        this.$message({
          message: '请选择订单',
          type: 'warning'
        });
      } else {
        const _this = this.$refs.form5;
        _this.dialog = true
      }
    },
    checkboxT(row, rowIndex) {
      return row.id !== 1
    },
    openConfirm() {
      this.$alert("确认打款？", "", {
        confirmButtonText: "确定",
        callback: (action) => {
          this.$message({
            type: "info",
            message: `action: ${action}`,
          });
        },
      });
    },
    editSkuPrice(data){
      this.isAdd = false
      const _this = this.$refs.form7
      _this.form = {
        id: data.id,
        price:data.cartInfoMap.truePrice,
        cartNum:data.cartInfoMap.cartNum,
        storeName:data.cartInfoMap.productInfo.storeName,
        sku:data.cartInfoMap.productInfo.attrInfo.sku,
        barCode:data.cartInfoMap.productInfo.attrInfo.barCode,
        truePrice:0,
      }
      _this.dialog = true
    }
  }
}
</script>

<style scoped lang="scss">
.container {
  height: calc(100% - 80px);
  position: absolute;
  overflow: auto;
  width: calc(100% - 20px);

  .order-caculate {
    font-size: 14px;
    color: #909399;
    border-top: 1px solid #f0f0f0;
    padding: 20px 10px;

    .caculate-title {
      display: inline-block;
      margin-right: 50px;
    }

    .caculate-num {
      font-size: 20px;
      color: #ff4949;
    }
  }

  .el-table th {
    background-color: #fafafa;
  }
}

.footer-contains {
  position: absolute;
  display: -ms-flexbox;
  display: flex;
  background-color: #f6f6f6;
  bottom: 0;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  z-index: 999;
  padding: 0 20px 0 13px;
}

/*打印单样式编辑*/
.order-list {
  /*  height: 297mm;*/
  margin: 0 auto;
  width: 210mm;

  .order-title {
    height: 16mm;
    line-height: 16mm;
    font-size: 8mm;
    font-weight: bolder;
    text-align: center;
  }

  .order-info {
    span {
      display: inline-block;
      padding: 0 0 10px 0;
      font-size: 3mm;
    }

    span.info {
      width: 60mm;
    }
  }

  .el-table--small th, .el-table--small td {
    padding: 4px 0;
  }
}
</style>
